package archer.application.core.api.internal.system;

import archer.application.core.entity.system.Rule;
import archer.application.core.service.system.RuleService;
import archer.application.core.api.BaseController;
import archer.framework.protocol.result.ExecuteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dendi
 * @date 16/7/4
 */
@RestController
@RequestMapping(value = "/api/v*/internal/system/rule")
@Transactional
public class RuleApi extends BaseController {
    @Autowired
    RuleService ruleService;

    @RequestMapping("store")
    public ExecuteResult store(Rule rule) {

        return ruleService.store(rule);
    }

    @RequestMapping("delete")
    public ExecuteResult delete(String id) {

        return ruleService.delete(id);
    }

    @RequestMapping("deleteAll")
    public ExecuteResult deleteAll(String ids) {

        return ruleService.deleteAll(split(ids));
    }

    @RequestMapping("findPagedList")
    public ExecuteResult findPagedList(String queryCondition) {

        return ruleService.findPagedList(asCondition(queryCondition));
    }

    @RequestMapping("find")
    public ExecuteResult find(String id) {
        return success(Rule.find.byId(id));
    }

    @RequestMapping("enable")
    public ExecuteResult enable(String id) {

        return ruleService.enable(id);
    }

    @RequestMapping("enableAll")
    public ExecuteResult enableAll(String ids) {

        return ruleService.enableAll(split(ids));
    }

}
